#set(tableComment = table.getComment())
#set(primaryKeyType = table.getPrimaryKey().getPropertySimpleType())
#set(entityClassName = table.buildEntityClassName())
#set(entityVarName = firstCharToLowerCase(entityClassName))
#set(serviceVarName = firstCharToLowerCase(table.buildServiceClassName()))
package #(packageConfig.controllerPackage);

import com.mybatisflex.core.paginate.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import jakarta.annotation.Resource;
import #(packageConfig.entityPackage).#(entityClassName);
import #(packageConfig.servicePackage).#(table.buildServiceClassName());
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.validation.annotation.Validated;
import cn.dev33.satoken.annotation.SaCheckLogin;
import #(packageConfig.basePackage).dto.#(entityClassName)PageQueryDTO;
import #(packageConfig.basePackage).dto.#(entityClassName)SaveOrUpdateDTO;

/**
 * #(table.getComment()) 控制层。
 *
 * @author #(javadocConfig.getAuthor())
 */
@Validated
@SaCheckLogin
@RestController
@RequestMapping("#(table.buildControllerRequestMappingPrefix())/#(firstCharToLowerCase(entityClassName))")
public class #(table.buildControllerClassName()){

    @Resource
    private #(table.buildServiceClassName()) #(serviceVarName);

    /**
     * 新增数据
     *
     * @param #(entityVarName)SaveOrUpdateDTO 新增/更新参数对象
     */
    @PostMapping("save")
    public R<String> save(@RequestBody #(entityClassName)SaveOrUpdateDTO #(entityVarName)SaveOrUpdateDTO) {
        #(serviceVarName).save(#(entityVarName)SaveOrUpdateDTO);
        return R.success();
    }

     /**
     * 根据id更新#(tableComment)
     *
     * @param #(entityVarName)SaveOrUpdateDTO 保存/更新参数对象
     */
    @PutMapping("update")
    public R<String> update(@RequestBody #(entityClassName)SaveOrUpdateDTO #(entityVarName)SaveOrUpdateDTO) {
        #(serviceVarName).updateById(#(entityVarName)SaveOrUpdateDTO);
        return R.success();
    }


    /**
     * 根据id删除#(tableComment)
     *
     * @param id 主键id
     */
    @DeleteMapping("remove/{id}")
    public R<String> remove(@PathVariable #(primaryKeyType) id) {
       #(serviceVarName).removeById(id);
       return R.success();
    }


    /**
     * 根据id获取#(tableComment)
     *
     * @param id 主键id
     */
    @GetMapping("getInfo/{id}")
    public R<#(entityClassName)> getInfo(@PathVariable #(primaryKeyType) id) {
        #(entityClassName) #(entityVarName) = #(serviceVarName).getInfo(id);
        return R.success(#(entityVarName));
    }

    /**
     * 分页查询#(tableComment)。
     *
     * @param #(entityVarName)PageQueryDTO 分页参数对象
     */
    @GetMapping("page")
    public R<Page<#(entityClassName)>> page(#(entityClassName)PageQueryDTO #(entityVarName)PageQueryDTO) {
        Page<#(entityClassName)> page = #(serviceVarName).page(#(entityVarName)PageQueryDTO);
        return R.success(#(page));
    }

}
